﻿// -------------------------------------------------------------------------
//    @FileName         :    NFOnlineService.cpp
//    @Author           :    gaoyi
//    @Date             :    2025-04-02
//    @Email			:    445267987@qq.com
//    @Module           :    NFOnlineService
//
// -------------------------------------------------------------------------

#include "NFOnlineService.h"

#include <NFSession.h>
#include <proto_svr_onlinesvr.pb.h>
#include <NFComm/NFPluginModule/NFCheck.h>
#include <NFComm/NFPluginModule/NFIConfigModule.h>
#include <NFServerComm/NFServerCommon/NFIServerMessageModule.h>

#include "NFPlayer.h"
#include "proto_svr_common.nanopb.h"
#include "ZoneMergeDescEx.h"

int NFOnlineService::TryAccOnlineReq(NFSession* pSession, int transId)
{
    NFServerConfig* pConfig = FindModule<NFIConfigModule>()->GetAppConfig(NF_ST_LOGIC_SERVER);
    NF_ASSERT(pConfig);
    CHECK_NULL(0, pSession);

    proto_ff::Proto_Zone2OnLineLoginReq req;
    req.set_zone_id(pSession->GetZoneID());
    req.set_player_uin(pSession->GetUIN());
    req.set_platform_type(pSession->GetPlatformType());

    FindModule<NFIServerMessageModule>()->SendTransToOnlineServer(NF_ST_LOGIC_SERVER, ZoneMergeDescEx::Instance()->GetMergeZoneId(pSession->GetZoneID()), E_ZONE2ONLINE_LOGIN_REQ, req, pSession->GetUIN(), transId);
    return 0;
}

int NFOnlineService::SendSSSyncOnlineReq(NFPlayer* pPlayer)
{
    CHECK_NULL(0, pPlayer);
    proto_ff::Proto_SSOnlineSyncNtf ntf;
    auto pCache = ntf.add_data();
    pCache->set_zone_id(pPlayer->GetRoleBase()->world_id);
    pCache->set_player_uin(pPlayer->GetRoleBase()->uin);
    pPlayer->MakeRoleCache(pCache->mutable_role());
    pPlayer->SendMsgToOnlineServer(E_SS_ONLINE_ROLE_SYNC_NTF, ntf);
    return 0;
}

int NFOnlineService::SendSSRegOnlineReq(NFPlayer* pPlayer)
{
    CHECK_NULL(0, pPlayer);
    proto_ff::Proto_SSOnlineRegNtf ntf;
    ntf.mutable_data()->set_zone_id(pPlayer->GetRoleBase()->world_id);
    ntf.mutable_data()->set_player_uin(pPlayer->GetRoleBase()->uin);
    pPlayer->MakeRoleCache(ntf.mutable_data()->mutable_role());
    pPlayer->SendMsgToOnlineServer(E_SS_ONLINE_ROLE_REGISTER_NTF, ntf);
    return 0;
}

int NFOnlineService::SendSSExitOnlineReq(NFPlayer* pPlayer)
{
    CHECK_NULL(0, pPlayer);
    proto_ff::Proto_SSOnlineExitNtf ntf;
    ntf.set_zone_id(pPlayer->GetRoleBase()->world_id);
    ntf.set_player_uin(pPlayer->GetRoleBase()->uin);
    ntf.set_role_id(pPlayer->GetRoleID());
    pPlayer->SendMsgToOnlineServer(E_SS_ONLINE_ROLE_EXIT_NTF, ntf);
    return 0;
}
